import {graphDataTransformer} from '../../modules/graph/utils/data'

export default {
  prefix: '/graph',
  configs: {
    /* 获取图谱 */
    getGraphByProjectId(projectId) {
      return {
        path: `/${projectId}`,
        mapper: graphDataTransformer
      }
    },

    /* 插入实体 */
    graphInsertNode(data) {
      console.log("插入检测:" + JSON.stringify(data))
      return {
        path: '/insertNode',
        method: 'POST',
        data
      }
    },
    /* 插入关系 */
    graphInsertRel(data) {
      return {
        path: '/insertRel',
        method: 'POST',
        data
      }
    },

    /* 删除实体 */
    graphDeleteNode(nodeId, projectId) {
      return {
        path: '/deleteNode',
        method: 'POST',
        data: {nodeId, projectId}
      }
    },
    /* 删除关系 */
    graphDeleteRel(relationId, projectId) {
      return {
        path: '/deleteRel',
        method: 'POST',
        data: {relationId, projectId}
      }
    },
    /* 级联删除实体 */
    graphDeleteNodeCascade(nodeId, projectId) {
      return {
        path: '/cascadeDeleteNode',
        method: 'POST',
        data: {nodeId, projectId}
      }
    },

    /* 更新实体 */
    graphUpdateNode(data) {
      return {
        path: '/updateNode',
        method: 'POST',
        data
      }
    },
    /* 更新关系 */
    graphUpdateRel(data) {
      return {
        path: '/updateRel',
        method: 'POST',
        data
      }
    },

    /* 保存布局 */
    updateLayout(data) {
      return {
        path: '/updateLayout',
        method: 'POST',
        data
      }
    },

    /* 查询相关的项目 */
    getProjectQuery(question) {
      return {
        path: `/projectQuery`,
        data: question,
        method: 'POST'
      }
    },

    /* 通过CSV文件新增实体和关系 */
    insertNodeAndRelationByCSV(data) {
      console.log("接口传递值data: " + JSON.stringify(data))
      const formData = new FormData()
      let backUrl = ''
      formData.append('file',data.file)
      formData.append('projectId',data.projectId)
      formData.append('relationName ',data.relationName)
      formData.append('relationWidth ',data.relationWidth )
      if(data.signNodeRelation){
        backUrl = '/importCSVNode'
        formData.append('nodeId',data.nodeId)
        formData.append('color','#63d6fb')
        formData.append('group',data.group)
        // formData.append('group',"概念1")
        formData.append('myGroup',data.myGroup)
        formData.append('textSize',data.textSize)
        formData.append('radius',data.radius)
        // formData.append('relationName',"123")
        formData.append('name ',data.mainName)
      }
      else{
        formData.append('fmyGroup',data.fmyGroup )
        formData.append('smyGroup ',data.smyGroup  )
        backUrl = '/importCSVRelation'
        console.log("执行了上传关系接口："+backUrl)
        console.log("执行了上传关系接口："+JSON.stringify(formData))
      }
      return {
        path: backUrl,
        method: 'POST',
        data: formData,
        headers: {'Content-Type': 'multipart/form-data'}
      }

    },

    /* 获取节点类别 */
    getGroupClass() {
      return
    },
    getNodes(data) {
      return {
        path: `/getNodeList?projectId=${data.projectId}&group=${data.group}&size=${data.size}`,
        // data: data,
        method: 'POST'
      }
    },
  }
}
